package com.project.controller;

import com.project.bean.NewBean;
import com.project.service.INewService;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("new")
public class NewController {
    @Autowired
    private INewService newService;
    /**搜索*/
    @GetMapping("findByTitle")
    public List<NewBean> findByTitle(String title){
        return newService.findByTitleLike(title);
    }
    /**发布*/
    @PostMapping("add")
    public String add(NewBean newBean){
        newService.add(newBean);
        return "发布成功";
    }
    /**置顶*/
    @PutMapping("upd")
    public String upd(Integer id,Integer status){
        newService.upd(id,status);
        if(status==1){
            return "已置顶";
        }else {
            return "取消置顶";
        }
    }
    /**置顶列表排序*/
    @GetMapping("newSort")
    public List<NewBean> newSort(){
        return newService.newSort();
    }
    /**新闻评论数量*/
    @GetMapping("findById")
    public NewBean findById(Integer newId){
        return newService.findById(newId);
    }
}
